//>> 对条件变量进行封装

#pragma once

#include <iostream>

#include <pthread.h>

namespace MyCond
{

    class Cond
    {
    private:
        pthread_cond_t _cond;
        pthread_mutex_t _mutex;

    public:
        Cond(const pthread_mutex_t &_out_mutex) : _mutex(_out_mutex)
        {
            if (::pthread_cond_init(&_cond, nullptr) != 0)
            {
                std::cout << "默认构造失败！" << std::endl;
            }
        }
        void Wait()
        {
            if (pthread_cond_wait(&_cond, &_mutex) != 0)
            {
                std::cout << "Wait 失败！" << std::endl;
            }
        }

        void Notify()
        {
            if (pthread_cond_signal(&_cond))
            {
                std::cout << " Nptify失败！" << std::endl;
            }
        }
        ~Cond()
        {
            if (::pthread_cond_destroy(&_cond) != 0)
            {
                std::cout << "析构失败！" << std::endl;
            }
        }
    }
}
